//
//  CZStatusOriginalView.swift
//  WeiBoNew
//
//  Created by 秦川 on 16/5/14.
//  Copyright © 2016年 秦川. All rights reserved.
//

import UIKit

class CZStatusOriginalView: UIView {

    var statusViewModel: CZStatusViewModel? {
        didSet {
            //  设置用户头像
            if let url = statusViewModel?.status?.user?.profile_image_url  {
                userImageView.sd_setImageWithURL(NSURL(string: url), placeholderImage: UIImage(named: "avatar_default_big"))
            }
            screenNameLabel.text = statusViewModel?.status?.user?.screen_name
            contentLabel.text = statusViewModel?.status?.text
            contentLabel.numberOfLines = 0
            timeLabel.text = "刚刚"
            sourceLabel.text = statusViewModel?.sourceContent
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //  MARK:  懒加载控件
    //  用户头像
    private lazy var userImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //  认证类型等级
    private lazy var verifiedTypeImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //  昵称
    private lazy var screenNameLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15)
    //  会员等级
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //  时间
    private lazy var timeLabel: UILabel = UILabel(textColor: UIColor.orangeColor(), textFont: 12)
    //  来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.lightGrayColor(), textFont: 12)
    
    //  微博内容
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 14)
    
    private func setupUI(){
     backgroundColor = UIColor.whiteColor()
        //  添加控件
        addSubview(userImageView)
        addSubview(verifiedTypeImageView)
        addSubview(screenNameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        //  设置约束
        userImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(StatusTableViewCellMargin)
            make.leading.equalTo(self).offset(StatusTableViewCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        verifiedTypeImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(userImageView.snp_trailing)
            make.centerY.equalTo(userImageView.snp_bottom)
        }
        
        screenNameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(userImageView)
            make.leading.equalTo(userImageView.snp_trailing).offset(StatusTableViewCellMargin)
        }
        mbrankImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(screenNameLabel)
            make.leading.equalTo(screenNameLabel.snp_trailing).offset(StatusTableViewCellMargin)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(userImageView.snp_bottom)
            make.leading.equalTo(userImageView.snp_trailing).offset(StatusTableViewCellMargin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLabel)
            make.leading.equalTo(timeLabel.snp_trailing).offset(StatusTableViewCellMargin)
        }
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(userImageView.snp_bottom).offset(StatusTableViewCellMargin)
            make.leading.equalTo(userImageView)
            make.trailing.equalTo(self).offset(-StatusTableViewCellMargin)
//            make.height.equalTo(80)
        }
       self.snp_makeConstraints { (make) -> Void in
        make.bottom.equalTo(contentLabel.snp_bottom).offset(StatusTableViewCellMargin)
        }

    }
}
